package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.Icon;
import com.ytjj.qmyx.admin.model.request.IconRequest;
import com.ytjj.qmyx.admin.model.response.IconResponse;
import com.ytjj.qmyx.admin.service.IconService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 图标资源配置
 */
@RestController
@RequestMapping("/icon")
public class IconController {
    @Resource
    private IconService iconService;

    /**
     * 创建图标资源
     * @param icon
     * @return
     */
    @PostMapping("/create")
    @OperLog(operModule = "图标资源管理", operDesc = "新增图标资源" , operType = SysLogConstants.OPERATION_ADD)
    public CommonResult create(@RequestBody Icon icon){
        return iconService.create(icon);
    }

    /**
     * 删除图标资源
     * @param id
     * @return
     */

    @PostMapping("/delete")
    @OperLog(operModule = "图标资源管理", operDesc = "删除图标资源" , operType = SysLogConstants.OPERATION_DELETE)
    public CommonResult delete(@RequestParam("id") Integer id){
        return iconService.delete(id);
    }

    /**
     * 查询图标资源
     * @param iconRequest
     * @return
     */
    @PostMapping("/selectList")
    @OperLog(operModule = "图标资源管理", operDesc = "图标资源列表查询" , operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult selectList(@RequestBody IconRequest iconRequest){
        if(iconRequest.getPageNum() == null || iconRequest.getPageSize() == null){
            //默认分页
            iconRequest.setPageNum(0);
            iconRequest.setPageSize(10);
        }
        CommonPage<IconResponse> page = iconService.selectList(iconRequest);
        return CommonResult.success(page,"查询成功");
    }

    /**
     * 更新图标资源状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/updateStatus")
    @OperLog(operModule = "图标资源管理", operDesc = "更新图标资源显示状态" , operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateStatus(@RequestParam("id") Integer id,@RequestParam("status") Integer status){
        return iconService.updateStatus(id, status);
    }

    /**
     * 更新图标资源
     * @param icon
     * @return
     */
    @OperLog(operModule = "图标资源管理", operDesc = "更新图标资源" , operType = SysLogConstants.OPERATION_UPDATE)
    @PostMapping("/update")
    public CommonResult update(@RequestBody Icon icon){
        return iconService.update(icon);
    }
}
